
/*
 * Copyright (C) 2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: XMLIntegerField.java 187 2009-11-12 18:27:01Z archie.cobbs $
 */

package org.dellroad.sidekar.xml;

import org.dellroad.sidekar.IntegerField;

/**
 * Container for a {@link IntegerField}'s value during the Sidekar XML import/export process.
 */
class XMLIntegerField extends XMLAtomicField<Integer> {

    private int value;

    // Used during unmarshalling
    private XMLIntegerField(XMLItem xmlItem) {
        super(xmlItem);
    }

    // Used during unmarshalling
    private XMLIntegerField(XMLField xmlField) {
        super(xmlField);
    }

    // Used during marshalling
    public XMLIntegerField(String name, int value) {
        super(name);
        this.value = value;
    }

    // Used during unmarshalling
    @Override
    public Integer getObjectValue() {
        return this.value;
    }

    // Used during marshalling
    @Override
    public boolean hasDefaultValue() {
        return this.value == 0;
    }

    // Used during unmarshalling
    public static XMLIntegerField newInstance(Object obj) {
        return obj instanceof XMLItem ? new XMLIntegerField((XMLItem)obj) : new XMLIntegerField((XMLField)obj);
    }
}

